﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WestWorldRemake.Characters;
using WestWorldRemake.Messaging;

namespace WestWorldRemake.States
{
    class StandardMinionStates
    {
        public class StandardMinionGlobalState : State<StandardMinion>
        {
            private StandardMinionGlobalState() { }
            private static StandardMinionGlobalState _Instance;

            public static StandardMinionGlobalState Instance
            {
                get
                {
                    if (_Instance == null)
                        _Instance = new StandardMinionGlobalState();
                    return _Instance;
                }
            }

            public override void Enter(StandardMinion entity)
            {
            }
            public override void Execute(StandardMinion entity)
            {
                if (entity.IsHungry())
                {
                    entity.StateMachine.ChangeState(GoEat.Instance);
                }
                else if (entity.IsTired())
                {
                    entity.StateMachine.ChangeState(GoRest.Instance);
                }
                else if (entity.CanLevelUp())
                {
                    if ((new Random().NextDouble() > .4))
                        entity.StateMachine.ChangeState(LevelUp.Instance);
                    else
                        Utilities.WriteText(entity, "Trying so hard to level up!");
                }
                else if ((new Random().NextDouble() > .15))
                {
                    entity.StateMachine.ChangeState(Worship.Instance);
                }
                else
                    Utilities.WriteText(entity, "Wandering around Madison...");
            }
            public override void Exit(StandardMinion entity)
            {
            }

            public override Iffy OnMessage(StandardMinion entity, Telegram t)
            {
                return Iffy.No;
            }
        }

        public class GoEat : State<StandardMinion>
        {
            private GoEat() { }
            private static GoEat _Instance;

            public static GoEat Instance
            {
                get
                {
                    if (_Instance == null)
                        _Instance = new GoEat();
                    return _Instance;
                }
            }

            public override void Enter(StandardMinion entity)
            {
                entity.Location = LocationType.TrojanCenter;
                Utilities.WriteText(entity, "*slobber slobber slobber* So hungry...");
            }
            public override void Execute(StandardMinion entity)
            {
                entity.Eat();
                Utilities.WriteText(entity, "*gobble* *slurp* *gobble*");
            }
            public override void Exit(StandardMinion entity)
            {
            }

            public override Iffy OnMessage(StandardMinion entity, Telegram t)
            {
                return Iffy.No;
            }
        }

        public class GoRest : State<StandardMinion>
        {
            private GoRest() { }
            private static GoRest _Instance;

            public static GoRest Instance
            {
                get
                {
                    if (_Instance == null)
                        _Instance = new GoRest();
                    return _Instance;
                }
            }

            public override void Enter(StandardMinion entity)
            {
                entity.Location = LocationType.HighRise;
                Utilities.WriteText(entity, "So... tired... *shuffle* *shuffle*");
            }
            public override void Execute(StandardMinion entity)
            {
                entity.Sleep();
                Utilities.WriteText(entity, "zzzzzzzzzzzz.....");
            }
            public override void Exit(StandardMinion entity)
            {
                Utilities.WriteText(entity, "Feeling so much better, must go wander.");
            }

            public override Iffy OnMessage(StandardMinion entity, Telegram t)
            {
                return Iffy.No;
            }
        }

        public class Worship : State<StandardMinion>
        {
            private Worship() { }
            private static Worship _Instance;

            public static Worship Instance
            {
                get
                {
                    if (_Instance == null)
                        _Instance = new Worship();
                    return _Instance;
                }
            }

            public override void Enter(StandardMinion entity)
            {
            }
            public override void Execute(StandardMinion entity)
            {
                entity.Location = LocationType.Downtown;
                Utilities.WriteText(entity, "*chanting* Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn");
                entity.IncreaseDevoutness(1.0);
            }
            public override void Exit(StandardMinion entity)
            {
            }

            public override Iffy OnMessage(StandardMinion entity, Telegram t)
            {
                return Iffy.No;
            }
        }

        public class LevelUp : State<StandardMinion>
        {
            private LevelUp() { }
            private static LevelUp _Instance;

            public static LevelUp Instance
            {
                get
                {
                    if (_Instance == null)
                        _Instance = new LevelUp();
                    return _Instance;
                }
            }

            public override void Enter(StandardMinion entity)
            {
            }
            public override void Execute(StandardMinion entity)
            {
                EntityManager mgr = EntityManager.Instance;
                Utilities.WriteText(entity, "Gah I'm levellin' up even more!!!!!!");
                Apostle newEntity = new Apostle(entity, entity.Location);
                mgr.LevelEntity(entity, newEntity);
            }
            public override void Exit(StandardMinion entity)
            {
            }

            public override Iffy OnMessage(StandardMinion entity, Telegram t)
            {
                return Iffy.No;
            }
        }
    }
}
